package com.bole.controller;


import com.bole.dao.ContentTypeDao;
import com.bole.dto.content.DicContentTypeDto;
import com.bole.pojo.DicContentTypeDo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("contenttype")
@Api(value = "广告类型管理api")
public class ContentTypeController {

    @Autowired
    private ContentTypeDao contentTypeDao;

    @GetMapping("getContentTypeInfo")
    @ApiOperation(value = "查询全部广告",notes = "查询全部广告")
    public List<DicContentTypeDto> getContentInfo() {
        List<DicContentTypeDo> all = contentTypeDao.findAll();
        ArrayList<DicContentTypeDto> dicContentTypeDtoArrayList = new ArrayList<>();
        for (DicContentTypeDo dicContentTypeDo : all) {
            DicContentTypeDto contentTypeDto = new DicContentTypeDto();
            BeanUtils.copyProperties(dicContentTypeDo, contentTypeDto);
            dicContentTypeDtoArrayList.add(contentTypeDto);
        }
        return dicContentTypeDtoArrayList;

    }

    @PostMapping("saveContentTypeInfo")
    @ApiOperation(value = "保存分类",notes = "保存分类")
    @ApiImplicitParam(name = "contentTypeDo",value = "分类对象",required = true,dataTypeClass = DicContentTypeDo.class)
    public void saveContentCateInfo(@RequestBody DicContentTypeDo contentTypeDo) {
        DicContentTypeDo dicContentTypeDo = contentTypeDao.save(contentTypeDo);
        DicContentTypeDto contentTypeDto = new DicContentTypeDto();
        BeanUtils.copyProperties(dicContentTypeDo, contentTypeDto);
    }

    @PostMapping("toUpdate")
    @ApiOperation(value = "分类回显",notes = "分类回显")
    @ApiImplicitParam(name = "id",value = "分类id",required = true,dataTypeClass = Long.class)
    public DicContentTypeDto toUpdate(@RequestParam("id") Long id) {
        DicContentTypeDo dicContentTypeDo = contentTypeDao.findById(id).get();
        DicContentTypeDto contentTypeDto = new DicContentTypeDto();
        BeanUtils.copyProperties(dicContentTypeDo, contentTypeDto);
        return contentTypeDto;
    }

    @PostMapping("updateContentCateInfo")
    @ApiOperation(value = "修改分类信息",notes = "修改分类信息")
    @ApiImplicitParam(name = "contentTypeDo",value = "分类对象",required = true,dataTypeClass = DicContentTypeDo.class)
    public void updateContentCateInfo(@RequestBody DicContentTypeDo contentTypeDo) {
        DicContentTypeDo dicContentTypeDo = contentTypeDao.save(contentTypeDo);
        DicContentTypeDto contentTypeDto = new DicContentTypeDto();
        BeanUtils.copyProperties(dicContentTypeDo, contentTypeDto);
    }

    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除广告类型",notes = "批量删除广告类型")
    @ApiImplicitParam(name = "idss",value = "品牌对象",required = true,dataTypeClass = Long.class)
    public void deleteBatch(@RequestParam("idss") List<Long> idss) {
        contentTypeDao.deleteBatch(idss);
    }



}
